/*
 * Copyright (C) 2012-2013 Matthias Zeimer and the miniframes project group.
 * All rights reserved. 
 * 
 * Licensed under the Eclipse Public License, Version 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.opensource.org/licenses/EPL-1.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package de.miniframes.minivalues;

import static org.junit.Assert.*;

import java.util.Locale;

import org.junit.Test;

/**
 * <p>
 * This is a test-suite to test the base features of {@link Value}. To put this
 * test in a real scenario, the test will use {@link DomainValue} and
 * {@link TechnicalValue} to test these features instead of building not
 * recommend sub-classes of Value itself.
 * </p>
 * 
 * @author Matthias Zeimer
 * @version 1
 * @since 0.1, 12.01.2013
 */
public class ValueTest {

    @Test
    public void formatTest_REMOVE_ME() {
        assertEquals("Hallo Otto", String.format("Hallo %s", "Otto"));
        assertEquals("Hallo Otto", String
                .format("Hallo %s", "Otto", "not used"));
        assertEquals("Hallo", String.format("Hallo", "Otto", "not used"));
        assertEquals("", String.format("", "Otto", "not used"));
        assertEquals("Hallo Horst", String.format("Hallo %3$s", "Otto",
                "not used", "Horst"));
    }

    @Test
    public void aDomainValueExampleTest() {
        InvoiceNumber out = InvoiceNumber.valueOf(42);
        InvoiceNumber equalsToOut = InvoiceNumber.valueOf(42);

        assertEquals("42", out.toString());
        assertEquals("Default is result of toString()", "42", out
                .toLocalisedString(Locale.UK));

        assertEquals(out, equalsToOut);
        assertEquals(equalsToOut, out);
        assertEquals(out.hashCode(), equalsToOut.hashCode());
        assertEquals(out.toString(), equalsToOut.toString());

        InvoiceNumber notEqualsToOut = InvoiceNumber.valueOf(23);

        assertFalse(out.equals(notEqualsToOut));

        assertTrue(out.compareTo(out) == 0);

        assertTrue(out.compareTo(equalsToOut) == 0);
        assertTrue(equalsToOut.compareTo(out) == 0);

        assertTrue(out.compareTo(notEqualsToOut) > 0);
        assertTrue(notEqualsToOut.compareTo(out) < 0);
    }

    /**
     * <p>
     * A suggested {@link DomainValue} for test purposes: The number of an
     * invoice.
     * </p>
     * 
     * <p>
     * This test-type satisfies all restrictions of a value-type and offers a
     * full featured variant.
     * </p>
     * 
     * @author Matthias Zeimer
     * @version 2
     * @since 0.1, 12.01.2013
     */
    public static final class InvoiceNumber extends DomainValue<InvoiceNumber> {

        private static final long serialVersionUID = 4337566180128015686L;

        /**
         * For serialisation only.
         */
        private InvoiceNumber() {
            super();
        }

        private InvoiceNumber(int numberAsInt) {
            super("%d", numberAsInt);
        }

        public static InvoiceNumber valueOf(int numberAsInt) {
            if (numberAsInt < 0) {
                throw new IllegalArgumentException(
                        "numberAsInt must be greater than 0.");
            }

            return new InvoiceNumber(numberAsInt);
        }
    }
}
